package demo1;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class Demo1 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        User user = new User();
        user.sayHello();
        //缺点：写死了，换个别的类或实现就要改代码

        //反射
        Class cls=Class.forName("demo1.User");
        User obj=(User)cls.newInstance();
        obj.sayHello();


        //Spring
        AnnotationConfigApplicationContext context=new AnnotationConfigApplicationContext("demo1");
        context.getBean(User.class);
        User user2=context.getBean(User.class);
        user2.sayHello();

    }
}
